/**
 *
 */
package gemini.basic.batch;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * General class for all batch job in FKR project.
 *
 */
public abstract class GmnJob extends QuartzJobBean {
    private final Logger logger = LoggerFactory.getLogger(GmnJob.class);

    /* (non-Javadoc)
     * @see org.springframework.scheduling.quartz.QuartzJobBean#executeInternal(org.quartz.JobExecutionContext)
     */
    @Override
    protected void executeInternal(JobExecutionContext context)
            throws JobExecutionException {

        // get batch name
        String batchName = getBatchName();
        batchName = batchName != null ? batchName : context.getJobDetail().getName();
        logger.debug("{} started.",batchName);
        // Executes the batch.
        try {
            /*SchedulerContext jcontext = context.getScheduler().getContext();
            paProcess = (PAErstellungProzess) jcontext.get("paProcess");*/
            boolean resultExecute = executeImpl(context);
            
            if (resultExecute) {
                logger.info("{} ends without error(s)",context.getJobDetail().getName());
            } else {
                logger.info("{} ends with error(s)",context.getJobDetail().getName());
            }
        } catch (Exception e) {
        	
            logger.error("{} encounters exception:{}",
                    context.getJobDetail().getName(), e.getMessage());
        }

    }

    /**
     * <p>
     * Abstract method to execute batch job. all extended classes have to implement the
     * bussiness inside this method.
     * </p>
     *
     * @param context The execution job data.
     * @return <code>True</code>. If batch ran successfully <code>False</code>.Otherwise
     */
    protected abstract boolean executeImpl(JobExecutionContext context);

    /**
     * <p>
     * Get name of the batch. It describe briefly function of the batch rather than name of
     * execution job
     * </p>
     *
     * @return briefly description of the batch in I18N
     */
    protected abstract String getBatchName();


	
}
